<template>
  <div class="app-container">
    <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-width="300px">
      <el-form-item label="是否特价商品" prop="litemall_withdraw_switch">
        <el-radio-group v-model="dataForm.litemall_withdraw_switch">
          <el-radio :label="'true'">是</el-radio>
          <el-radio :label="'false'">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="最低提现金额" prop="litemall_withdraw_downLimit">
        <el-input v-model="dataForm.litemall_withdraw_downLimit" class="input-width" />
      </el-form-item>
      <el-form-item label="最高提现金额" prop="litemall_withdraw_upLimit">
        <el-input v-model="dataForm.litemall_withdraw_upLimit" class="input-width" />
      </el-form-item>
      <el-form-item label="必须满足最低提现金额的倍数" prop="litemall_withdraw_mustFold">
        <el-radio-group v-model="dataForm.litemall_withdraw_mustFold">
          <el-radio :label="'true'">是</el-radio>
          <el-radio :label="'false'">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="申请后到账最迟天数" prop="litemall_withdraw_entryDays">
        <el-input v-model="dataForm.litemall_withdraw_entryDays" />
      </el-form-item>
      <el-form-item>
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="update">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { listWithdraw, updateWithdraw } from '@/api/config'

export default {
  name: 'ConfigWithdraw',
  data() {
    return {
      dataForm: {
        litemall_withdraw_switch: true,
        litemall_withdraw_downLimit: 20,
        litemall_withdraw_upLimit: 1000000,
        litemall_withdraw_mustFold: true,
        litemall_withdraw_entryDays: 2
      },
      rules: {
        litemall_withdraw_switch: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        litemall_withdraw_downLimit: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        litemall_withdraw_upLimit: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        litemall_withdraw_mustFold: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        litemall_withdraw_entryDays: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init: function() {
      listWithdraw().then(response => {
        this.dataForm = response.data.data
      })
    },
    cancel() {
      this.init()
    },
    update() {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.doUpdate()
      })
    },
    doUpdate() {
      updateWithdraw(this.dataForm)
        .then(response => {
          this.$notify.success({
            title: '成功',
            message: '提现参数配置成功'
          })
        })
        .catch(response => {
          this.$notify.error({
            title: '失败',
            message: response.data.errmsg
          })
        })
    }
  }
}
</script>
<style scoped>
  .input-width {
    width: 50%;
  }
  .info {
    margin-left: 15px;
  }
</style>
